package com.fhx.core.utils

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.fhx.core.R

class DialogUtil {
    companion object {
        fun show(context: Context, contentView: View, style: Int): Dialog {
            val dialog = Dialog(context, style)
            dialog.setContentView(contentView)
            dialog.setCancelable(true)
            dialog.setCanceledOnTouchOutside(true)
            return dialog
        }

        fun show(context: Context, contentView: View): Dialog {
            val dialog = Dialog(context, R.style.dialog)
            dialog.setContentView(contentView)
            dialog.setCancelable(false)
            dialog.setCanceledOnTouchOutside(false)
            return dialog
        }

        fun showMessageDialog(context: Context, msg: String) {
            val builder = AlertDialog.Builder(context)
            builder.setTitle("提示");
            builder.setMessage(msg)
            builder.setPositiveButton("确定", null)
            val dialog = builder.show()
            //因为app把colorAccent改成了白色，按钮默认使用的这个颜色，所以就看不清了，必须改成黑色
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK)
        }

        fun showChooseDialog(context: Context, msg: String,lis: DialogInterface.OnClickListener) {
            val builder = AlertDialog.Builder(context)
            builder.setTitle("提示");
            builder.setMessage(msg)
            builder.setPositiveButton("确定", lis)
            builder.setNegativeButton("取消",null)
            val dialog = builder.show()
            //因为app把colorAccent改成了白色，按钮默认使用的这个颜色，所以就看不清了，必须改成黑色
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK)
            dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK)
        }
    }
}